<?php




/**
* Lists entities in images
*/

#int mktime ( [int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]] )
/*
Array
(
    [0] => 2012
    [1] => 02
    [2] => 13
    [3] => 21
    [4] => 57
    [5] => 53
)
2012-02-13 21:57:53
*/
$per_day = 864000;
$today = preg_split('/[^\d]+/is', date('Y-m-d H:i:s'));
#print_r($today);
$today_begining = mktime(0, 0, 0, $today[1], $today[2], $today[0]);
$today_ending = $today_begining+$per_day;
$yesterday_begining = $today_begining - $per_day;
$yesterday_ending = $today_begining;
#echo 'Totay: '.$today_begining;

$week_begining = $today_ending - $per_day * 7;

# Last 30 days
$last30days_begining = $today_ending - $per_day * 30;
$last30days_ending = $today_ending;

$span_selected = $variable->get('span', 'string', 'all');

$spans = array(
	'all' => null,
	'today' => $today_begining,
	'yesterday' => $today_begining-$per_day, # between this and $today_beging
	'week' => 0, # This week
	'last7days' => 0,
	'lastweek' => 0,
	'month' => 0,
	'last30days' => 0,
	'lastmonth' => 0,
);
$span = array();
foreach($spans as $s => $span_unit) { $span[$s] = ($span_selected==$s);}
#print_r($span);
#print_r($spans);
#die(date('Y-m-d H:i:s'));


# When a user will cancel add/edit forms, we will try to come back here
url::remember();

# Begin the paginator along with: images
# Parameter: GET[], and per page
$pagination = new pagination('pg', IMAGES_PER_PAGE);

$images = new images();

$search_images = $variable->remember_string('search_images');
$smarty->assign('search_images', $search_images);

$condition = new condition();

$condition->add('FULL', array(
	"e.subdomain_id={$subdomain_id}", # Bind the records
	"e.is_active='Y'", # Do not remove this
	#"e.is_approved='Y'", # Optionally use this flag
	
	# Modified duration via calculated time
	
	# Today
	$span['today']?"(e.modified_on BETWEEN {$today_begining} AND {$today_ending})":'',
	
	# Yesterday
	$span['yesterday']?"(e.modified_on BETWEEN {$yesterday_begining} AND {$yesterday_ending})":'',
	
	# This week
	$span['week']?"(e.modified_on BETWEEN {$week_begining} AND {$today_ending})":'',
	
	# last30days
	#"(e.modified_on BETWEEN {$last30days_begining} AND {$last30days_ending})",
	
	"e.modified_on!=0",
));

# Compulsory conditions
$condition->add('AND', array(
	#'e.search_field' => 'Y', # Partial %contents%
));

# List out the entries
$entries = $images->list_recently_modified_images(
	$condition,
	$from_index=$pagination->begining_entry(),
	$pagination->per_page()
);

# Pagination helper
$pagination->set_total($images->total_entries());
$smarty->assignByRef('pagination', $pagination);

# Assign to Smarty: Lists
$smarty->assignByRef('imagess', $entries);
?>